# node镜像打包
FROM node:latest AS frontend-builder
# 设置工作目录
WORKDIR /build-app
# 复制所有文件
COPY . .
# 安装依赖并打包
RUN npm install && npm run build


# nginx打包

# 镜像打包
FROM nginx:latest
# 暴露端口
EXPOSE 80
# 工作目录
WORKDIR /app

# 复制nginx配置文件
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 删除nginx默认的html文件
RUN rm -rf /usr/share/nginx/html
# 重建nginx的html文件夹
RUN mkdir /usr/share/nginx/html
# 复制打包后的文件
COPY --from=frontend-builder /build-app/dist /usr/share/nginx/html

# 启动
CMD ["nginx", "-g", "daemon off;"]
